/**
 * 
 */
package com.ptma.model;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

/**
 * @author YahyaArshad
 * 
 */
@Entity
@Table(name = "APPLICATION_VERSION")
@XmlRootElement(name = "version")
@XmlAccessorType(XmlAccessType.NONE)
public class ApplicationVersion implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue
	@Column(name = "version_id")
	private Long id = 0L;

	@Column(name = "upload_time")
	private Timestamp uploadTime = new Timestamp(System.currentTimeMillis());

	@XmlElement
	@Column(name = "uninstall_previous")
	private boolean isUninstallPrevious = false;

	@Cascade(value = { CascadeType.SAVE_UPDATE })
	@OneToMany
	@JoinColumn(name = "fk_application_version_id", referencedColumnName = "version_id")
	private List<Notification> notifications;

	@Cascade(value = { CascadeType.SAVE_UPDATE })
	@OneToMany
	@JoinColumn(name = "fk_application_version_id", referencedColumnName = "version_id")
	private List<Installation> installations;

	@XmlElement
	@Column(name = "version_comment")
	private String versionComment;

	@XmlElementWrapper(name = "defects")
	@XmlElement(name = "defect")
	@OneToMany
	@Cascade(value = { CascadeType.SAVE_UPDATE })
	@JoinColumn(name = "fk_application_version_id", referencedColumnName = "version_id")
	private List<VersionComment> comments;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public boolean isUninstallPrevious() {
		return isUninstallPrevious;
	}

	public void setUninstallPrevious(boolean isUninstallPrevious) {
		this.isUninstallPrevious = isUninstallPrevious;
	}

	public List<Installation> getInstallations() {
		return installations;
	}

	public void setInstallations(List<Installation> installations) {
		this.installations = installations;
	}

	public List<VersionComment> getComments() {
		return comments;
	}

	public void setComments(List<VersionComment> comments) {
		this.comments = comments;
	}

	public ApplicationVersion() {

	}

	public String getVersionComment() {
		return versionComment;
	}

	public void setVersionComment(String versionComment) {
		this.versionComment = versionComment;
	}

	public List<Notification> getNotifications() {
		return notifications;
	}

	public void setNotifications(List<Notification> notifications) {
		this.notifications = notifications;
	}

	public Timestamp getUploadTime() {
		return uploadTime;
	}

	public void setUploadTime(Timestamp uploadTime) {
		this.uploadTime = uploadTime;
	}

}
